package com.zoro.barn.inner.service.documentsql.document.controller;

import com.zoro.barn.api.documentsql.document.BarnDocumentService;
import com.zoro.barn.dto.documentsql.document.DocumentQueryDto;
import com.zoro.barn.inner.service.documentsql.document.service.DocumentInfoService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhaoxingwu
 */
@RestController
@RequestMapping("document-query")
public class BarnDocumentServiceController implements BarnDocumentService {

    private final DocumentInfoService documentInfoService;

    public BarnDocumentServiceController(DocumentInfoService documentInfoService) {
        this.documentInfoService = documentInfoService;
    }


    @Override
    public DocumentQueryDto countByProduct(DocumentQueryDto dto) {
        Integer count = this.documentInfoService.countByProduct(dto.getProductId());
        DocumentQueryDto result = new DocumentQueryDto();
        result.setDocumentCount(count == null ? 0 : count);
        return result;
    }

    @Override
    public DocumentQueryDto countByProject(DocumentQueryDto dto) {
        Integer count = this.documentInfoService.countByProject(dto.getProjectId());
        DocumentQueryDto result = new DocumentQueryDto();
        result.setDocumentCount(count == null ? 0 : count);
        return result;
    }
}
